import { Meta, ArgsTable, Canvas, Story, Markdown } from '@storybook/addon-docs';
import { useArgs } from '@storybook/client-api';
import { Toggle } from '@zendeskgarden/react-forms';
import { ToggleStory } from './stories/ToggleStory';
import { commonArgs, commonArgTypes, fieldSubcomponents } from './stories/common';
import README from '../README.md';

<Meta
  title="Packages/Forms/Toggle"
  component={Toggle}
  subcomponents={{ ...fieldSubcomponents }}
  args={{
    ...commonArgs,
    hasHint: false
  }}
  argTypes={{
    disabled: { control: 'boolean' },
    ...commonArgTypes
  }}
  parameters={{
    design: {
      allowFullscreen: true,
      type: 'figma',
      url: 'https://www.figma.com/file/6g87L4FdKZTA3knt3Rsfdx/Garden?node-id=103%3A20264'
    }
  }}
/>

# API

<ArgsTable />

# Demo

## Uncontrolled

<Canvas>
  <Story name="Uncontrolled">{args => <ToggleStory {...args} />}</Story>
</Canvas>

## Controlled

<Canvas>
  <Story name="Controlled" args={{ checked: false }}>
    {args => {
      const updateArgs = useArgs()[1];
      const handleChange = event => updateArgs({ checked: !args.checked });
      return <ToggleStory {...args} onChange={handleChange} />;
    }}
  </Story>
</Canvas>

<Markdown>{README}</Markdown>
